﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using zichan.BLL;

namespace zichan.Controllers
{
    public class ClassLogsController : BaseController
    {
        // GET: ClassLogs
        public ActionResult Index(string className,string keyWord,DateTime? sdt,DateTime? edt, int? page, int? pageSize, int? pageCount, int? selectedPage)
        {
            page = page ?? 1;
            pageSize = pageSize ?? 10;
            if (selectedPage.HasValue)
                page = selectedPage;
            if (pageCount.HasValue)
                page = page <= pageCount ? page : pageCount;
            if (page < 1) page = 1;
            ViewBag.page = page;
            ViewBag.pageSize = pageSize;
            ViewBag.selectedPage = selectedPage;
            List<SelectListItem> items = new List<SelectListItem> { new SelectListItem { Value = "10", Text = "10" }, new SelectListItem { Value = "20", Text = "20" }, new SelectListItem { Value = "50", Text = "50" }, new SelectListItem { Value = "100", Text = "100" } };
            ViewBag.pageSizes = new SelectList(items, "Value", "Text", ViewBag.pageIndex);

            //ViewBag.backurl = Request.UrlReferrer.PathAndQuery;//获取主机绝对路径加查询条件
            List<SelectListItem> classNameItem = new List<SelectListItem> { new SelectListItem { Value = "公司分类", Text = "公司分类" }, new SelectListItem { Value = "资产分类", Text = "资产分类" }, new SelectListItem { Value = "机房分类", Text = "机房分类" }, new SelectListItem { Value = "机柜用途分类", Text = "机柜用途分类" } };
            ViewBag.classNames =new SelectList(classNameItem,"Value","Text",className);
            ViewBag.className = className;
            ViewBag.keyWord = keyWord;
            ViewBag.sdt = sdt;
            ViewBag.edt = edt;
            if (sdt.HasValue)
                ViewBag.sdt = string.Format("{0:yyyy/M/d}", sdt);
            if(edt.HasValue)
                ViewBag.edt = string.Format("{0:yyyy/M/d}", edt);
            return View(ClassLogService.ClassLogsList(className,keyWord,sdt,edt,pageSize.Value,page.Value));
        }
    }
}